package com.nuaa.likesystem.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nuaa.likesystem.common.ErrorCode;
import com.nuaa.likesystem.constant.UserConstant;
import com.nuaa.likesystem.exception.BusinessException;
import com.nuaa.likesystem.mapper.UserMapper;
import com.nuaa.likesystem.model.entity.User;
import com.nuaa.likesystem.service.UserService;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Service;

/**
* @author 11352
* @description 针对表【user】的数据库操作Service实现
* @createDate 2025-04-20 15:26:20
*/
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User>
    implements UserService {

	@Override
	public User getLoginUser(HttpServletRequest request) {

		Object userObj = request.getSession()
		                        .getAttribute(UserConstant.USER_LOGIN_STATE);
		User currentUser = (User) userObj;
		if (currentUser == null || currentUser.getId() == null) {
			throw new BusinessException(ErrorCode.NOT_LOGIN_ERROR);
		}

		return currentUser;
	}
}




